package pl.ericpol.kernel.schemas;

import org.apache.log4j.LogManager;
import org.apache.log4j.Logger;

import pl.ericpol.environment.devices.Device;

public class Action implements Comparable<Action>{

	private static Logger logger = LogManager.getLogger(Action.class);
	
	private Device device;
	private int needValue;
	private byte priority;
	private boolean isDone = false;

	public Action(Device device, int needValue, byte priority) {
		this.device = device;
		this.needValue = needValue;
		this.priority = priority;
	}	

	public void execute() {
		device.setState(needValue);
		logger.info("System set state to device : "+device.getId()+" state: "+needValue);
	}

	public Device getDevice() {
		return device;
	}

	public void setDevice(Device device) {
		this.device = device;
	}

	public int getNeedValue() {
		return needValue;
	}

	public void setNeedValue(int needValue) {
		this.needValue = needValue;
	}

	public byte getPriority() {
		return priority;
	}

	public void setPriority(byte priority) {
		this.priority = priority;
	}

	public boolean isDone() {
		return isDone;
	}

	public void setDone(boolean isDone) {
		this.isDone = isDone;
	}	

	@Override
	public int compareTo(Action o) {
		if (priority>o.priority)
			return 1;
		else {
			if (priority<o.priority)
				return -1;
			else
				return 0;
		}
	}

	

}
